Python 3.10 introduced a specific syntax using the "or" operator (X | Y
) to represent a union of types. This syntax has the same
functionality as typing.Union
, but it is more concise and easier to read.
Using typing.Union
is more verbose and less convenient. It can also create inconsistencies when different parts of the codebase use
different syntaxes for the same type.